package com.panda.cn.utils.result;

/**
 * @author: Mr.Yan
 * @create: 2020/10/21
 * @description: 返回结果编码与含义
 */
public enum RCodeEnum {
    /**
     * 调用成功
     */
    SUCCESS(0, "成功"),

    /**
     * 调用失败
     */
    FAIL(-1, "失败"),
    /**
     * 调用异常
     */
    FAIL_THROW(300, "异常"),

    /**
     * 调用失败
     */
    FAIL_TOKNE(500, "令牌异常");
    /**
     * 返回编码
     */
    private Integer code;

    /**
     * 编码对应的消息
     */
    private String msg;

    RCodeEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 获取枚举类型的编码值
     */
    public Integer code() {
        return this.code;
    }

    /**
     * 获取枚举类型的编码含义
     */
    public String msg() {
        return this.msg;
    }

    /**
     * 根据枚举名称--获取枚举编码
     */
    public static Integer getCode(String name) {
        for (RCodeEnum resultCode : RCodeEnum.values()) {
            if (resultCode.name().equals(name)) {
                return resultCode.code;
            }
        }
        return null;
    }

}
